﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cesave.DistributedServices.PermisosModule.WindowsHost.ViewModelBase;
using Cesave.DistributedServices.PermisosModule.WindowsHost.Views.Catalogs.Areas;
using Cesave.DistributedServices.PermisosModule.WindowsHost.Resources;

namespace Cesave.DistributedServices.PermisosModule.WindowsHost.ViewModels.Catalogs.Areas
{
	public partial class AreasViewModel
		: ObservableObject
	{

		#region Private properties

		private AreasView _areasView;

		#endregion

		public AreasViewModel(AreasView areasView)
		{
			if (areasView == null)
				throw new ArgumentNullException("areasView");
			_areasView = areasView;
			WireUpEvents();
			InitModels();
		}

		private void InitModels()
		{
			LoadJuntas();
		}

		private void WireUpEvents()
		{
			PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(AreasViewModel_PropertyChanged);
			_areasView.Load += LoadView;
			_areasView.closeButton.Click += (sender, e) =>
			{
				_areasView.Close();
			};
			_areasView.saveButton.Click += SaveArea;
			_areasView.areaBindingNavigatorSaveItem.Click += SaveArea;
			_areasView.bindingNavigatorAddNewItem.Click += AddArea;
			_areasView.newButton.Click += AddArea;
		}

		private void LoadView(object sender, EventArgs e)
		{
			_areasView.Text = WindowTitles.AreasWindowTitle;
		}

		private void FocusDefaultControl()
		{
			_areasView.ActiveControl = _areasView.nombreUltraTextEditor;
		}

		private void AreasViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
		{
			switch (e.PropertyName)
			{
				case "Juntas":
					OnJuntasPropertyChanged();
					break;
				case "Junta":
					OnJuntaPropertyChanged();
					break;
				case "Area":
					OnAreaPropertyChanged();
					break;
				case "Areas":
					OnAreasPropertyChanged();
					break;
				default:
					break;
			}
		}
	}
}